package org.achartengine.internal.chart;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.RectF;
import android.graphics.Shader;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.Arrays;

/* loaded from: classes2.dex */
public class g extends a {
    private static final int a = 10;
    private static final long serialVersionUID = 1;
    private org.achartengine.internal.model.a b;
    private org.achartengine.internal.renderer.a c;
    private float[] d = null;
    private RectF e = null;
    private int f = -1;
    private double g;

    @Override // org.achartengine.internal.chart.a
    public int a(int i) {
        return 10;
    }

    public g(org.achartengine.internal.model.a aVar, org.achartengine.internal.renderer.a aVar2) {
        this.b = aVar;
        this.c = aVar2;
    }

    @Override // org.achartengine.internal.chart.a
    public void a(Canvas canvas, int i, int i2, int i3, int i4, Paint paint) {
        int i5;
        float f;
        RectF rectF;
        float f2;
        int i6;
        int i7;
        String[] strArr;
        int i8;
        paint.setAntiAlias(this.c.q());
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(this.c.g());
        int u = this.c.u();
        if (this.c.l() && u == 0) {
            u = i4 / 5;
        }
        int i9 = u;
        int i10 = i + i3;
        int c = this.b.c();
        this.g = Utils.DOUBLE_EPSILON;
        String[] strArr2 = new String[c];
        for (int i11 = 0; i11 < c; i11++) {
            this.g += this.b.b(i11);
            strArr2[i11] = this.b.c(i11);
        }
        int a2 = this.c.m() ? a(canvas, this.c, strArr2, i, i10, i2, i3, i4, i9, paint, true) : i9;
        int i12 = (i2 + i4) - a2;
        a(this.c, canvas, i, i2, i3, i4, paint, false, 0);
        double min = Math.min(Math.abs(i10 - i), Math.abs(i12 - i2));
        Double.isNaN(min);
        double t = this.c.t();
        Double.isNaN(t);
        int i13 = (int) (min * 0.35d * t);
        if (i13 <= 0) {
            return;
        }
        int i14 = (i + i10) / 2;
        int i15 = (i12 + i2) / 2;
        float f3 = i13;
        float f4 = f3 * 0.9f;
        float f5 = f3 * 1.1f;
        RectF rectF2 = new RectF(i14 - i13, i15 - i13, i14 + i13, i13 + i15);
        this.e = rectF2;
        ArrayList arrayList = new ArrayList();
        this.d = new float[c];
        int i16 = 0;
        float f6 = 0.0f;
        float f7 = 0.0f;
        while (i16 < c) {
            paint.setColor(this.c.a(i16).b());
            float b = (float) this.b.b(i16);
            double d = b;
            int i17 = i16;
            double d2 = this.g;
            Double.isNaN(d);
            float f8 = (float) ((d / d2) * 360.0d);
            if (i17 != this.f) {
                paint.setShader(new RadialGradient(i14, i15, f3 * 2.0f, paint.getColor(), this.c.a(i17).a(), Shader.TileMode.CLAMP));
                canvas.drawArc(rectF2, f7, f8, true, paint);
                paint.setShader(null);
                if (b > 0.0f) {
                    i5 = i17;
                    f = f8;
                    rectF = rectF2;
                    f2 = f3;
                    i6 = i15;
                    i7 = i14;
                    strArr = strArr2;
                    i8 = c;
                    a(canvas, this.b.c(i17), this.c, arrayList, i14, i15, f4, f5, f7, f, i, i10, paint);
                } else {
                    i5 = i17;
                    f = f8;
                    rectF = rectF2;
                    f2 = f3;
                    i6 = i15;
                    i7 = i14;
                    strArr = strArr2;
                    i8 = c;
                }
            } else {
                i5 = i17;
                f = f8;
                rectF = rectF2;
                f2 = f3;
                i6 = i15;
                i7 = i14;
                strArr = strArr2;
                i8 = c;
                f6 = f7;
            }
            f7 += f;
            this.d[i5] = f7;
            i16 = i5 + 1;
            f3 = f2;
            strArr2 = strArr;
            c = i8;
            rectF2 = rectF;
            i15 = i6;
            i14 = i7;
        }
        RectF rectF3 = rectF2;
        float f9 = f3;
        int i18 = i15;
        int i19 = i14;
        String[] strArr3 = strArr2;
        int i20 = this.f;
        if (i20 > -1) {
            paint.setColor(this.c.a(i20).b());
            double b2 = (float) this.b.b(this.f);
            double d3 = this.g;
            Double.isNaN(b2);
            float f10 = (float) ((b2 / d3) * 360.0d);
            new RectF(rectF3).inset(-5.0f, -5.0f);
            float f11 = (f10 / 2.0f) + f6;
            int i21 = -5;
            int i22 = 5;
            if (f11 > 90.0f) {
                if (f11 <= 180.0f) {
                    i21 = 5;
                } else {
                    if (f11 <= 270.0f) {
                        i21 = 5;
                    }
                    paint.setShadowLayer(20.0f, i21, i22, -12303292);
                    paint.setShader(new RadialGradient(i19, i18, f9 * 2.0f, paint.getColor(), this.c.a(this.f).a(), Shader.TileMode.CLAMP));
                    canvas.drawArc(rectF3, f6, f10, true, paint);
                    paint.setShader(null);
                    paint.clearShadowLayer();
                    a(canvas, this.b.c(this.f), this.c, arrayList, i19, i18, f4, f5, f6, f10, i, i10, paint);
                }
            }
            i22 = -5;
            paint.setShadowLayer(20.0f, i21, i22, -12303292);
            paint.setShader(new RadialGradient(i19, i18, f9 * 2.0f, paint.getColor(), this.c.a(this.f).a(), Shader.TileMode.CLAMP));
            canvas.drawArc(rectF3, f6, f10, true, paint);
            paint.setShader(null);
            paint.clearShadowLayer();
            a(canvas, this.b.c(this.f), this.c, arrayList, i19, i18, f4, f5, f6, f10, i, i10, paint);
        }
        arrayList.clear();
        a(canvas, this.c, strArr3, i, i10, i2, i3, i4, a2, paint, false);
    }

    @Override // org.achartengine.internal.chart.a
    public void a(Canvas canvas, org.achartengine.internal.renderer.b bVar, float f, float f2, int i, Paint paint) {
        canvas.drawRect(f, f2 - 5.0f, f + 10.0f, f2 + 5.0f, paint);
    }

    @Override // org.achartengine.internal.chart.a
    /* renamed from: b */
    public org.achartengine.internal.model.b a(float f, float f2) {
        if (this.e.contains(f, f2) && this.d != null) {
            double degrees = Math.toDegrees(Math.atan2(f - this.e.centerX(), this.e.centerY() - f2)) - 90.0d;
            if (degrees < Utils.DOUBLE_EPSILON) {
                degrees += 360.0d;
            }
            int binarySearch = Arrays.binarySearch(this.d, (float) degrees);
            if (binarySearch <= -1) {
                binarySearch = (-binarySearch) - 1;
            }
            this.f = binarySearch;
            if (binarySearch < 0) {
                return null;
            }
            org.achartengine.internal.model.b bVar = new org.achartengine.internal.model.b(this.b.c(binarySearch), Double.valueOf(this.b.b(this.f)));
            bVar.a(this.b.b(this.f) / this.g);
            return bVar;
        }
        this.f = -1;
        return null;
    }

    public org.achartengine.internal.model.a a() {
        return this.b;
    }

    public org.achartengine.internal.renderer.a b() {
        return this.c;
    }
}
